//
//  ZZStatusToolBar.swift
//  sina
//
//  Created by 张鹏 on 16/5/28.
//  Copyright © 2016年 ZP. All rights reserved.
//

import UIKit

class ZZStatusToolBar: UIView {

    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setUpUI()
        backgroundColor = UIColor(white: 0.95, alpha: 1)

        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    private func setUpUI() {
    
    //设置UI
    addSubview(repostBtn)
        
        addChildBtn(repostBtn, title: "转发", imageName: "timeline_icon_retweet")
        addChildBtn(commentsBtn, title: "评论", imageName: "timeline_icon_comment")
        addChildBtn(attitudesBtn, title: "赞", imageName: "timeline_icon_like")
    

        repostBtn.snp_makeConstraints { (make) in
            make.left.top.bottom.equalTo(self)
        }
        commentsBtn.snp_makeConstraints { (make) in
            make.left.equalTo(repostBtn.snp_right)
            make.top.bottom.equalTo(repostBtn)
            make.width.equalTo(repostBtn.snp_width)
        }
        
        attitudesBtn.snp_makeConstraints { (make) in
            make.left.equalTo(commentsBtn.snp_right)
            make.top.bottom.equalTo(commentsBtn)
            make.right.equalTo(self)
            make.width.equalTo(repostBtn.snp_width)
        }
        
        
        //添加分割线
        let sepView1 = lineView()
        let sepView2 = lineView()
        let width = 1 / UIScreen.mainScreen().scale
        addSubview(sepView1)
        addSubview(sepView2)
        sepView1.snp_makeConstraints { (make) in
            make.left.equalTo(commentsBtn.snp_left)
            make.centerY.equalTo(self.snp_centerY)
            //黄金分割比  1 : 0.618
            make.height.equalTo(self.snp_height).multipliedBy(0.4)
            make.width.equalTo(width)
        }
        
        sepView2.snp_makeConstraints { (make) in
            make.left.equalTo(commentsBtn.snp_right)
            make.centerY.equalTo(self.snp_centerY)
            //黄金分割比  1 : 0.618
            make.height.equalTo(self.snp_height).multipliedBy(0.4)
            make.width.equalTo(width)
        }
        

        
        
    }
    
    
    private func lineView() -> UIView {
    
        let line = UIView()
        line.backgroundColor = UIColor.purpleColor()
    
        return line
    }
    
    
    private func addChildBtn(btn : UIButton, title : String, imageName : String) {
    
        btn.backgroundColor = UIColor.darkGrayColor()
        btn.titleLabel?.font = UIFont.systemFontOfSize(10)
        btn.setImage(UIImage(named: imageName), forState: .Normal)
        btn.setBackgroundImage(UIImage(named: ""), forState: .Normal)
        btn.setTitle(title, forState: .Normal)
        btn.setTitleColor(UIColor.darkGrayColor(), forState: .Normal)
        //自动适应
        btn.sizeToFit()
        
        //把btn添加到toolbar中
        self.addSubview(btn)
    }
    
    
    private lazy var repostBtn : UIButton = UIButton()
    private lazy var commentsBtn : UIButton = UIButton()
    private lazy var attitudesBtn : UIButton = UIButton()

}
